#include "widget.h"
#include "ui_widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    InitItem(ui->comboBox,"C:\\Code\\qt\\SpinBox_Attribute\\1.txt");
    InitItem(ui->comboBox_2,"C:\\Code\\qt\\SpinBox_Attribute\\2.txt");
    InitItem(ui->comboBox_3,"C:\\Code\\qt\\SpinBox_Attribute\\3.txt");
    ui->spinBox->setMinimum(1);
    ui->spinBox->setMaximum(10);
    ui->spinBox_2->setMinimum(1);
    ui->spinBox_2->setMaximum(10);
    ui->spinBox_3->setMinimum(1);
    ui->spinBox_3->setMaximum(10);
}

void Widget::on_pushButton_clicked()
{
    qDebug() << ui->label->text() << " " << ui->comboBox->currentData() << " " << ui->spinBox->value() << endl
             << ui->label_2->text() << " " << ui->comboBox_2->currentData() << " " << ui->spinBox_2->value() << endl
             << ui->label_3->text() << " " << ui->comboBox_3->currentData() << " " << ui->spinBox_3->value() << endl;
}


void Widget:: InitItem(QComboBox* comBox ,const std::string& path)
{
    std::ifstream ifs(path,std::ios_base::in);
    if(ifs.is_open() == false)
    {
        qDebug() << "ifs.is_open() == false";
        return ;
    }
    std::string line;
    while(std::getline(ifs,line))
    {
        comBox->addItem(QString::fromStdString(line));
    }
}


Widget::~Widget()
{
    delete ui;
}



